var articleDAL =require('../model/arcticleDAL')
var qs = require('querystring')
var url = require('url')
var articlescontroller ={
    article:function(req,res){
        var aid=req.query.aid;
        var users={aid:aid}
        articleDAL.article(users,function(err,results){
            if(err){
                console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                // console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    // console.log("1")
                    res.json({code:200,msg:'ok',data:results,results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    },
    author:function(req,res){
        var uid=req.query.uid;
        var users={uid:uid}
        articleDAL.author(users,function(err,results){
            if(err){
                // console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                // console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    // console.log("1")
                    res.json({code:200,msg:'ok',data:results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    },
    comment:function(req,res){
        var aid=req.query.aid;
        var users={aid:aid}
        // console.log('aid')
        articleDAL.comment(users,function(err,results){
            if(err){
                console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    console.log("1")
                    res.json({code:200,msg:'ok',data:results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    },
    commentown:function(req,res){
        var tid=req.query.tid;
        var content=req.query.content
        var uid=req.query.uid
        var tTime=req.query.tTime
        var likes=req.query.likes
        var users={tid:tid,content:content,uid:uid,tTime:tTime,likes:likes}
        // console.log('aid')
        articleDAL.commentown(users,function(err,results){
            if(err){
                console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    console.log("1")
                    res.json({code:200,msg:'ok',data:results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    },
    addFabulous:function(req,res){
        var tid=req.query.tid;
        var users={tid:tid}
        // console.log('aid')
        articleDAL.addFabulous(users,function(err,results){
            if(err){
                console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    console.log("1")
                    res.json({code:200,msg:'ok',data:results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    },
    delFabulous:function(req,res){
        var tid=req.query.tid;
        var users={tid:tid}
        // console.log('aid')
        articleDAL.delFabulous(users,function(err,results){
            if(err){
                console.log('数据查询错误')
                res.json({code:500,msg:'数据查询错误'})
            }else{
                console.log('查完数据')
                // console.log(results)
                if(results[0]){
                    console.log("1")
                    res.json({code:200,msg:'ok',data:results})
                }
                else{
                    res.json({code:200,msg:'ok',data:0})
                }
                
            }
        })
    }
}
module.exports = articlescontroller